//To merge two arrays and sort it.
class mergesort
	{
	public static void main(String [] args)
		{
		int []a={11,22,33,44};//
		int[] b={33,57,84};//
		int [] c=mergeSort(a,b);
		displayMergeSort(c);
		}
	public static int[] mergeSort(int[] x, int[] y)
		{
		int [] z= new int[x.length+y.length];
		int i=0,j=0,k=0;
		while(j<x.length || k<y.length||i<z.length)
			{
			if(x[j]<y[k])
				{
				z[i]=x[j];		
				i++;
				j++;
				}
			else if(x[j]>y[k])
				{
				z[i]=y[k];
				i++;
				k++;
				}
			else 
				{
				z[i]=y[k];
				i++;
				z[i]=x[j];
				k++;
				j++;
				}
			}
		return z;
		}
	public static void displayMergeSort(int[] a)
		{
		System.out.println("The sorted array is : ");
		for(int i=0;i<a.length+1;i++)
			System.out.println(a[i]);
		}
	
	}
				